package com.example.myprojectoffeixue;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class Mkadapter extends BaseAdapter {
    //码库列表的适配器
    private ArrayList<String> d;
    private LayoutInflater layoutInflater;
    private Context context;
    private String JDHType = "02";
    private String TVType = "04";
    private String KTType = "06";

    public Mkadapter(ArrayList<String> d, Context context) {
        super();
        this.d = d;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return d.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return d.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder h = null;
        MaKulistActivity mk = (MaKulistActivity) context;
        MyApplication m = (MyApplication) mk.getApplication();
        if (convertView == null) {
            h = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_hongwai, null);
            h.tv = (TextView) convertView.findViewById(R.id.tv_itemhongwai);
            h.iv = (ImageView) convertView.findViewById(R.id.iv_shebei);
            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }
        if (JDHType.equals(m.type)) {
            h.iv.setImageResource(R.drawable.jdh);
        } else if (TVType.equals(m.type)) {
            h.iv.setImageResource(R.drawable.dianshi);
        } else if (KTType.equals(m.type)) {
            h.iv.setImageResource(R.drawable.zykt);
        }
        h.tv.setText("码库" + d.get(position));
        return convertView;
    }


    class ViewHolder {
        TextView tv;
        ImageView iv;
    }


}

